﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace client.app
{
    public enum DXType
    {
        NORMAL = 0
    }

    public class DXInfo
    {
        public int Width { get; set; }
        public int Height { get; set; }
        public int[,] Dots { get; set; }

        public bool Check(int x, int y)
        {
            return new Rectangle(0, 0, Width, Height).Contains(x, y);
        }
        public bool Has(int x, int y)
        {
            return Check(x, y) && Dots[x, y] == 1;
        }
    }

    public static class DX
    {
        static Dictionary<DXType, Dictionary<int, DXInfo>> _bdDic = new Dictionary<DXType, Dictionary<int, DXInfo>>();
        static DX()
        {
            #region normal
            var normal = @"
0
0
,
0x
00
,
00
00
,
0x
00
00
,
00
00
00
,
x0x
000
000
,
00x
000
000
,
000
000
000
,
x0x
000
000
000
,
00x
000
000
000
,
000
000
000
000
";
            #endregion

            AddDic(DXType.NORMAL, normal);
        }
        static void AddDic(DXType type, string content)
        {
            _bdDic.Add(type, new Dictionary<int, DXInfo>());
            var blocks = content.Split(',');
            int no = 2;
            foreach (var block in blocks)
            {
                var info = new DXInfo();
                var lines = block.Replace("\r", "").Split('\n');
                var dots = new Dictionary<string, int>();
                foreach (var line in lines)
                {
                    var l = line.TrimEnd();
                    for (int i = 0, len = line.Length; i < len; i++)
                    {
                        var c = line[i];
                        if (c == '0')
                        {
                            dots.Add(i + "," + info.Height, 1);
                        }
                    }
                    if (l != "")
                    {
                        info.Width = Math.Max(l.Length, info.Width);
                        info.Height++;
                    }
                }
                info.Dots = new int[info.Width, info.Height];
                for (int x = 0; x < info.Width; x++)
                {
                    for (int y = 0; y < info.Height; y++)
                    {
                        info.Dots[x, y] = dots.ContainsKey(x + "," + y) ? 1 : 0;
                    }
                }
                _bdDic[type].Add(no, info);
                no++;
            }
        }

        public static DXInfo GetInfo(DXType type, int count)
        {
            return _bdDic[type][count];
        }
    }
}
